class MusicPlayer{
  var list: List[String] = Nil    
  var nowsong: String = ""       
  var mode: String = "loop" 
  def addsong(song: String): Unit = {
    list = list :+ song      
  }
  def removesong(song: String): Unit = {
    list = list.filter(_ != song)  
  }
  def play(): Unit = {
    nowsong = list.headOption.getOrElse("") 
  }
  def nextsong(): Unit = {
    mode match {
      case "loop" => loopPlayNext()
      case "shuffle" => shufflePlayNext()
      case "single" => singlePlayNext()
      case _ => println("当前播放模式未知")
    }
  }
   def loopPlayNext(): Unit = {
    val index = list.indexOf(nowsong) 
    if (index == list.length - 1) {       
      nowsong =list.headOption.getOrElse("")
    } else {                                   
      nowsong =list(index + 1)
    }
  }
  def shufflePlayNext(): Unit = {
     nowsong = scala.util.Random.shuffle(list).headOption.getOrElse("")
  }
  def singlePlayNext(): Unit = {
    if (list.contains(nowsong)) {
      nowsong = nowsong
    } else {
      nowsong =list.headOption.getOrElse("")
    }
  }
}